/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.ycl.st.load.startup;

import cn.ac.iie.di.ban.ycl.st.load.commons.RuntimeEnv;
import cn.ac.iie.di.ban.ycl.st.load.commons.RuntimeEnvException;
import cn.ac.iie.di.ban.ycl.st.load.exception.UpdateException;
import cn.ac.iie.di.ban.ycl.st.load.util.MongoHelper;
import cn.ac.iie.di.ban.ycl.st.load.util.SenderPool;
import cn.ac.iie.di.ban.ycl.st.load.util.StHelper;
import cn.ac.iie.di.ban.ycl.st.load.worker.Receiver;
import cn.ac.iie.di.datadock.rdata.exchange.client.core.REFieldType;
import cn.ac.iie.di.datadock.rdata.exchange.client.exception.REConnectionException;
import cn.ac.iie.di.datadock.rdata.exchange.client.v1.connection.REConnection;
import cn.ac.iie.di.datadock.rdata.exchange.client.v1.session.RESendSessionBuilder;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import org.apache.log4j.Logger;

/**
 *
 * @author zwlin
 */
public class StDbStartup {

    public static boolean isTest = false;
    private static final Logger logger = Logger.getLogger(StDbStartup.class.getName());

    private static SenderPool getSenderPool(String SendNamesrv, String SendTopic) throws REConnectionException {
        RESendSessionBuilder builder = (RESendSessionBuilder) new REConnection(SendNamesrv).getSendSessionBuilder(SendTopic);
        builder.addColumn("_id", REFieldType.String, true);
        builder.addColumn("wx_key_fng", REFieldType.String, true);
        builder.addColumn("_key", REFieldType.String, true);
        builder.addColumn("_spec", REFieldType.String, true);
        builder.addColumn("_ch", REFieldType.Long, true);
        builder.addColumn("ut", REFieldType.Long, true);
        builder.addColumn("ct", REFieldType.Long, true);
        return new SenderPool(builder);
    }

    public static void main(String[] args) throws RuntimeEnvException, UpdateException, REConnectionException {
        RuntimeEnv.init();
        logger.info("start");
        SenderPool[] pools = new SenderPool[1];
        pools[0] = getSenderPool(
                RuntimeEnv.getParamAsString(RuntimeEnv.RMQ_SEND1_NAMESRV),
                RuntimeEnv.getParamAsString(RuntimeEnv.RMQ_SEND1_TOPIC));
        Receiver receiver = new Receiver(
                RuntimeEnv.getParamAsString(RuntimeEnv.RMQ_RECEIVE_NAMESRV),
                RuntimeEnv.getParamAsString(RuntimeEnv.RMQ_RECEIVE_TOPIC),
                RuntimeEnv.getParamAsString(RuntimeEnv.RMQ_RECEIVE_GROUPNAME_PREFIX),
                pools);
        receiver.start();
        logger.info("连接成功");

    }
}
